package com.huifaapp.mall.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 品牌列表适配器
 */
public class MyCollectGridViewAdapter extends BaseAdapter{

	private Context context;
	private LayoutInflater inflater;
	private List<String> serviceareaList;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	private boolean isChenck=false;
	private ArrayList<String> ar=new ArrayList<String>();
	public MyCollectGridViewAdapter(Context context){//, List<String> serviceareaList) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.serviceareaList=serviceareaList;
	}
	@Override
	public int getCount() {
		return serviceareaList == null ? 0 : serviceareaList.size();
	}

	@Override
	public Object getItem(int position) {
		return serviceareaList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public List<String> getServiceareaList() {
		return serviceareaList;
	}

	public MyCollectGridViewAdapter setServiceareaList(List<String> serviceareaList) {
		this.serviceareaList = serviceareaList;
		return this;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.my_collect_item_gridview_adapter, null);
			holder = new ViewHolder();
			holder.iv_myCollect_imageshop= (ImageView) convertView.findViewById(R.id.iv_myCollect_imageshop);
			holder.tv_myCollect_name= (TextView) convertView.findViewById(R.id.tv_myCollect_name);
			holder.tv_myCollect_price= (TextView) convertView.findViewById(R.id.tv_myCollect_price);
			holder.tv_myCollect_ds_price= (TextView) convertView.findViewById(R.id.tv_myCollect_ds_price);
			holder.tv_myCollect_red_juan= (TextView) convertView.findViewById(R.id.tv_myCollect_red_juan);
			holder.tv_myCollect_Have_snapped_up= (TextView) convertView.findViewById(R.id.tv_myCollect_Have_snapped_up);
			holder.iv_myCollect_share= (ImageView) convertView.findViewById(R.id.iv_myCollect_share);
			holder.iv_myCollect_erweima= (ImageView) convertView.findViewById(R.id.iv_myCollect_erweima);
			holder.tv_myCollect_earn= (TextView) convertView.findViewById(R.id.tv_myCollect_earn);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		final String bean=serviceareaList.get(position);
		Log.e("数据","Gridviewbean=========="+bean);
		uploadimageview(holder.iv_myCollect_imageshop,bean,null,context);
		return convertView;
	}
	
	
	
	class ViewHolder {
		
		private ImageView iv_myCollect_imageshop;
		private TextView tv_myCollect_name;
		private TextView tv_myCollect_price;
		private TextView tv_myCollect_ds_price;
		private TextView tv_myCollect_red_juan;
		private TextView tv_myCollect_Have_snapped_up;
		private ImageView iv_myCollect_share;
		private ImageView iv_myCollect_erweima;
		private TextView tv_myCollect_earn;
	}

	public static void uploadimageview(final ImageView views, String url, String bili, Context c) {
		DisplayImageOptions HXOptions = new DisplayImageOptions.Builder()
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.considerExifParams(true)
				.bitmapConfig(Bitmap.Config.RGB_565).build();
		ImageLoader.getInstance().displayImage(url, views, HXOptions);
	}
}
